Hello and welcome.
In this lecture we will be implementing coalition detection.
So far we have created are pricks.
So at the moment when the ball bounces off the paddle and hits the brick nothing happens.
So what we're going to do is implement some kind of solution detection so that when it does hit the
brick it will break them or it will make them disappear from the campus.
So what we are going to try and do here we are going to implement something to check the centre of the
ball is colliding or touching with any of the bricks kinsell which is going to create some kind of detection
there.
So where by the ball the centre of the ball is touching or colliding with any and giving part of the
bricks again to save a bit of time so you don't have to watch me type the code.
I have already pre written the code here from line 86 to line ninety eight.
So what we got at work done here is create some kind of coalition detection function that will loop
through all the bricks and then compare every single breeks position with the ball's coordinate.
So as each frame or each break is drawn it will compare the position on the X and position on the Y.
All right so create it the function here called coalition detection again Wayne creative functions is
always a good idea to name your function closely related to the function or the activity you want the
function to perform.
So I call this completion detection so it would be detecting coalition.
So I've got a loop here.
So Same here.
You may recognize this look from our previous lectures as well.
So this for loop is saying that it will check for the column the calon value 0.
And if the column is less than the break call long count this here it all had one quick look.
So it will loop to and add 1.
She notices the count is low or has it or is less than the column count.
It had one each time plus bloss means equal out one time elapsed true.
The same applies for the row checks the row zero and f in this less than the brick row count.
Again it adds one each time so he does that each time he goes through the loop so each iteration is
timing all round them.
Do that on to the specified amount or count for the column or row has been met or asked.
I've created a variable here and giving it just the letter B.
What the variable will do.
The variable will be used to store the brick object in every iteration of the loop so the variable will
store the brick object in every loop of the coalition detections So every time it goes through this
floor trying to detect a coalition it will store the information in this variable.
All right so we've given the value of this variable.
He was sort of the breaks and then we've got an array here.
Pass it inside said the array.
We've got a column count and we've got another array here inside that we have the rule variable or count.
So we're saying that if the value of b does state or C distrait status of the B variable is equal to
1 and if the value of the x variable is greater than the B dot X and.
X is less then B.
X bloss 2 with the brick and Y is greater than the brick and is variable B.
And why.
And why is letting them be so if all these values are met the value of DIY.
But it was too deep why mouse.
Why.
And then the value of the status of that will be forced to.
So what this means is that the ex puts it when the exposition of the board is greater than the exposition
of the brick.
It'll draw the brick of the glue will detect the collusion.
So when the exposition of the ball is less than expositional it brick blocks this whiff which is what
I've done here.
Then this happens.
So when the y position of the ball at the y position of the ball is greater than the y position on the
break.
Then this happens.
All right so the y position of the ball when the where position of the ball is less than the position
of the break from the height.
Then there is value because to mine is the.
So here we have also what the State of the state has here.
Checks.
So when the status is set to zero that means the brick would have been hit by the ball.
So we want the brick to disappear by this status's one.
Then the brake is drawn on the screen than is the brick has not been hit yet but whereby this state
or zero it has been hit by the ball and it all disappear from the Cam so we can also track the detection
or the status of the coalition.
So what happens here is that we use the state US property to check for coalition.
The coalition has been detected.
So if the brake is active the status is set to one.
So we'll check to see if the coalition has happened.
If a coalition occurs this status will be set back to zero.
Okay so that means what that means is that the break will not because he's been hit it will not be painted
on drawn on the compass.
So this is how you will of date the coalition.
This is how you would check for the coalition so any break in hit value set to zero.
It doesn't get drawn again on the compass when the loop goes round.
It is excluded from the loop.
Alright that's it for this leg shot in this leg.
Sure we create a function to do some collision detection.
We all saw torched briefly on how to make the balls or the breaks disappear from the screen.
Once they have been hit with the ball we all saw some kind of tracking to check for the status of the
coalition so if a break has been hit the state is set to zero.
So when the loop cause is not painted or create or drawn game on become mass so when the brick is active
the status is one and then it can be created or drawn on the compass.
Thank you so much for watching.
Bye for now.